<Window x:Class="ScrumSprintMonitor.ConfigEditor.Views.ConfigurationView.ConfigurationWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ScrumSprintMonitor.ConfigEditor"
    xmlns:ConfigurationView="clr-namespace:ScrumSprintMonitor.ConfigEditor.Views.ConfigurationView"
    xmlns:converters="clr-namespace:ScrumSprintMonitor.ConfigEditor.Converters"
    xmlns:Behaviors="clr-namespace:ScrumSprintMonitor.UI.Wpf.Behaviors;assembly=ScrumSprintMonitor.UI.Wpf"
    Title="Configure Scrum Sprint Monitor"
    Background="Gray"
    Width="600" WindowStartupLocation="CenterScreen"
    Loaded="OnWindowLoaded" Activated="OnWindowActivated" MouseLeftButtonDown="OnWindowMouseLeftButtonDown">
    
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/ScrumSprintMonitor.UI.Wpf;component/Styles/FormResourceDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <local:XamlServiceLocator x:Key="serviceLocator" />
            
            <converters:NegatedValueConverter x:Key="NegatedValueConverter" />
        </ResourceDictionary>
    </Window.Resources>

    <Window.Style>
        <StaticResource ResourceKey="DefaultChrome"/>
    </Window.Style>

    <Grid DataContext="{Binding Path=ConfigurationViewModel, Source={StaticResource serviceLocator}}"
          Behaviors:BusyIndicatorBehavior.BusyState="{Binding IsBusy}"
          Behaviors:BusyIndicatorBehavior.TargetVisual="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}"
          Behaviors:BusyIndicatorBehavior.AddMargins="True">
        <DockPanel>
            <Grid DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="0" Content="_Team Foundation Server:" Target="{Binding ElementName=tfsServerNameComboBox}" />
                <ComboBox Grid.Column="1" Grid.Row="0" ItemsSource="{Binding Path=AvailableTfsServers}" SelectedItem="{Binding Path=TfsServerName}" x:Name="tfsServerNameComboBox" IsReadOnly="{Binding IsConfigurationWritable, Converter={StaticResource NegatedValueConverter}}" />

                <ContentControl Grid.Row="1" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" IsTabStop="False" Focusable="False">
                    <ContentControl.Content>
                        <Label Style="{StaticResource LabelStyle}">
                            <TextBlock>
                                <Bold>1) <Span/></Bold>Current Sprint
                            </TextBlock>
                        </Label>
                    </ContentControl.Content>
                </ContentControl>

                <Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="2" Content="_Configuration File:" Target="{Binding ElementName=configurationFileTextBox}" />
                <Grid Grid.Column="1" Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="configurationFileTextBox" Style="{StaticResource TextBoxStyle}" Grid.Column="0" Text="{Binding Path=ConfigurationFilePath}" IsReadOnly="{Binding IsConfigurationWritable, Converter={StaticResource NegatedValueConverter}}" ToolTip="Enter a path to the file (new or existing) that will be used to store the sprint configuration." />
                    <Button Command="{Binding BrowseSprintConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Grid.Column="1" Content="..." Padding="6,0" Margin="0,2" IsEnabled="{Binding IsConfigurationWritable}" />
                </Grid>
                <Button Command="{Binding EditSprintConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Grid.Row="3" Grid.ColumnSpan="2" HorizontalAlignment="Right" Content="Edit _Sprint Configuration..." Padding="6" Margin="0,2" />

                <ContentControl Grid.Row="4" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" IsTabStop="False" Focusable="False">
                    <ContentControl.Content>
                        <Label Style="{StaticResource LabelStyle}">
                            <TextBlock>
                                <Bold>2) <Span/></Bold>Team Members
                            </TextBlock>
                        </Label>
                    </ContentControl.Content>
                </ContentControl>

                <Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="5" Content="Configuration File:" Target="{Binding ElementName=teamMembersConfigurationTextBox}"/>
                <Grid Grid.Column="1" Grid.Row="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="teamMembersConfigurationTextBox" Style="{StaticResource TextBoxStyle}" Grid.Column="0" Text="{Binding Path=TeamMembersConfigurationFilePath}" IsReadOnly="{Binding IsConfigurationWritable, Converter={StaticResource NegatedValueConverter}}" ToolTip="Enter a path to the file (new or existing) that will be used to store the team members configuration." />
                    <Button Command="{Binding BrowseTeamMembersConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Grid.Column="2" Content="..." Padding="6,0" Margin="0,2" IsEnabled="{Binding IsConfigurationWritable}" />
                </Grid>
                <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.ColumnSpan="2" HorizontalAlignment="Right">
                    <Button Command="{Binding GenerateTeamMembersConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Content="_Generate file from current sprint..." Padding="6" Margin="0,2,6,2" ToolTip="Use this button to generate a base team-info.xml file with the team members found in the sprint query defined in step 1. Afterwards, you can use Microsoft Excel to fine tune the data in that file." />
                    <Button Command="{Binding EditTeamMembersConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Content="Edit in Microsoft E_xcel 2007..." Padding="6" Margin="0,2" />
                </StackPanel>

                <ContentControl Grid.Row="7" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" IsTabStop="False" Focusable="False">
                    <ContentControl.Content>
                        <Label Style="{StaticResource LabelStyle}">
                            <TextBlock>
                                <Bold>3) <Span/></Bold>General Presentation Options
                            </TextBlock>
                        </Label>
                    </ContentControl.Content>
                </ContentControl>

                <Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="8" Content="Configuration File:" Target="{Binding ElementName=presentationConfigurationTextBox}"/>
                <Grid Grid.Column="1" Grid.Row="8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="presentationConfigurationTextBox" Style="{StaticResource TextBoxStyle}" Grid.Column="0" Text="{Binding Path=PresentationConfigurationFilePath}" IsReadOnly="{Binding IsConfigurationWritable, Converter={StaticResource NegatedValueConverter}}" ToolTip="Enter a path to the file (new or existing) that will be used to store the UI presentation configuration." />
                    <Button Command="{Binding BrowsePresentationConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Grid.Column="2" Content="..." Padding="6,0" Margin="0,2" IsEnabled="{Binding IsConfigurationWritable}" />
                </Grid>
                <Button Command="{Binding EditPresentationConfigurationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Grid.Row="9" Grid.ColumnSpan="2" HorizontalAlignment="Right" Content="Edit _General Options..." Padding="6" Margin="0,2" />

                <Expander Grid.Row="10" Grid.ColumnSpan="2" Header="_Outlook Integration" Foreground="White" HeaderTemplate="{StaticResource ExpanderSeparator}">
                    <StackPanel>
                        <CheckBox x:Name="enableOutlookIntegrationCheckBox" IsChecked="{Binding Path=EnableOutlookIntegration}" Margin="6" IsEnabled="{Binding IsConfigurationWritable}">
                            <Label Style="{StaticResource LabelStyle}" Content="Enable Outlook integration for _Free/Busy information" Margin="0" Padding="0" Foreground="White" Target="{Binding ElementName=enableOutlookIntegrationCheckBox}" />
                        </CheckBox>
                        <CheckBox x:Name="considerOutlookTentativeAsFreeTimeCheckBox" IsChecked="{Binding Path=ConsiderOutlookTentativeAsFreeTime}" IsEnabled="{Binding IsConsiderOutlookTentativeAsFreeTimeEnabled}" Margin="6">
                            <Label Style="{StaticResource LabelStyle}" Content="Consider 'Tentative' _appointments to be free time" Margin="0" Padding="0" Foreground="White" Target="{Binding ElementName=considerOutlookTentativeAsFreeTimeCheckBox}" />
                        </CheckBox>
                    </StackPanel>
                </Expander>

                <Expander Grid.Row="11" Grid.ColumnSpan="2" Header="_Miscellaneous" Foreground="White" HeaderTemplate="{StaticResource ExpanderSeparator}">
                    <StackPanel>
                        <CheckBox x:Name="reportUnestimatedSprintBacklogItemsCheckBox" IsChecked="{Binding Path=ReportUnestimatedSprintBacklogItems}" Margin="6" IsEnabled="{Binding IsConfigurationWritable}">
                            <Label Style="{StaticResource LabelStyle}" Content="Report _unestimated sprint backlog items" Margin="0" Padding="0" Foreground="White" Target="{Binding ElementName=reportUnestimatedSprintBacklogItemsCheckBox}" />
                        </CheckBox>

                        <CheckBox x:Name="inPlanningModeCheckBox" IsChecked="{Binding Path=InPlanningMode}" Margin="6" IsEnabled="{Binding IsConfigurationWritable}">
                            <Label Style="{StaticResource LabelStyle}" Content="_Planning Mode" Margin="0" Padding="0" Foreground="White" Target="{Binding ElementName=inPlanningModeCheckBox}" />
                        </CheckBox>
                    </StackPanel>
                </Expander>
            </Grid>

            <Grid DockPanel.Dock="Bottom">
                <Button Command="{Binding ViewLogFileCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,0,6,0" Padding="16,4" Content="View _Log File..."/>

                <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,12,0,0">
                    <Button Command="{Binding OkCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Margin="6,0,0,0" Padding="16,4" IsDefault="True" Content="O_K"/>
                    <Button Command="{Binding CancelCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ConfigurationView:ConfigurationWindow}}}" Margin="6,0,0,0" Padding="16,4" IsCancel="True" Content="Cancel"/>
                </StackPanel>
            </Grid>
        </DockPanel>
    </Grid>
</Window>
